package 回溯法;

import java.sql.Struct;
import java.util.ArrayList;
import java.util.List;

/**
 * Copyright (C) 2023 思创数码科技股份有限公司
 * <p/>
 * 版权所有
 * <p/>
 * 类名　　  : 电话号码字母组合
 * 功能概要  :
 *
 * @author yangwk
 * @date 2024/5/31 16:22
 */
public class 电话号码字母组合 {
    public static String[] DIGIT = {"", "abc", "def", "ghi",  "jkl", "mno", "pqrs", "tuv", "", "wxyz"};


    public static List<String> combination(String arr, int index, StringBuilder path) {
        List<String> result = new ArrayList<>();
        if (arr.length() == 0) {
            return new ArrayList<>();
        }
        if (index >= arr.length()) {
            result.add(new String(path));
            return result;
        }
        char[] numbers = arr.toCharArray();
        int digitNum = Integer.parseInt(String.valueOf(numbers[index]));
        char[] chars = DIGIT[digitNum - 1].toCharArray();
        for (int j = 0; j < chars.length; j++) {
            char charVal = chars[j];
            path.append(charVal);
            result.addAll(combination(arr, index + 1, path));
            path.deleteCharAt(path.length() - 1);
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(combination("5", 0, new StringBuilder()));
    }

}
